package com.origin.ebuy.bargd.service.order.impl;

import java.sql.SQLException;

import com.alibaba.fastjson.JSONArray;
import com.origin.ebuy.bargd.dao.order.IOrderDao;
import com.origin.ebuy.bargd.dao.order.impl.OrderDaoImpl;
import com.origin.ebuy.bargd.service.order.IOrderService;

public class OrderServiceImpl implements IOrderService {

	IOrderDao dao = new OrderDaoImpl();

	/**
	 * @param gdId 商品id
	 * @param price 订单总价格
	 * @param uid 用户id
	 * @param gdNumber 商品数量 
	 */
	@Override
	public long insertOrder(String gdId, String price, 
			String uid, String gdNumber,String sf,String city,String address)
			throws SQLException {
		String[] cols = {"gd_id","price","u_id","gd_numbs","sf","city","address"};
		Object[] parames = {gdId,price,uid,gdNumber,sf,city,address};
		return dao.insert(cols, parames);
	}

	@Override
	public JSONArray queryAllOrders() throws SQLException {
		String[] cols = {"od.id","od.gd_id","od.price","od.date","od.state","od.gd_numbs","od.address","u.uname",
				"gd.name_gd","gd.imge_gd","od.sf","od.city"};
		String table = "orders od,users u,goods gd";
		String where = "od.gd_id=gd.id_gd and u.id=od.u_id";
		return dao.queryAllOrder(table, where, cols);
	}

	@Override
	public int updateOrderState(String id, String state) throws SQLException {
		return dao.updateOrderState(id, state);
	}

}
